﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DataBase
{
    public partial class ServerList : Form
    {
        public ServerList()
        {
            InitializeComponent();
        }

        private void ServerList_Load(object sender, EventArgs e)
        {
            BindData();
            dataGridView1.ClearSelection();
        }

        private void BindData()
        {
            this.dataGridView1.DataSource = AccessDAL.FindServerList();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ServerAdd serveradd = new ServerAdd(0);
            serveradd.ShowDialog();
            BindData();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int id= DataConvert.ToInt(dataGridView1.Rows[e.RowIndex].Cells[2].Value);
            if (e.ColumnIndex == 0)
            {
                
                ServerAdd serveradd = new ServerAdd(id);
                serveradd.ShowDialog();
                BindData();
            }
            if (e.ColumnIndex == 1)
            {
                MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
                DialogResult dr = MessageBox.Show("您确定要删除吗？", "删除", messButton);
                if (dr == DialogResult.OK)
                {
                    AccessDAL.DeleteById(id, "server");
                    BindData();
                }
            }
        }
    }
}
